package view.widget;

import java.util.ArrayList;

import util.Util;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shilehui.www.R;

import core.data.HelpDataInfomation;

public class HotspotNotificationBannerManager {
	
	private View hotspotNotificationBanner = null;
	private ArrayList<HelpDataInfomation> hotspostBuffer = null;
	private ArrayList<ImageView> hotspotImageNotificationViewBuffer = null;
	private Drawable unselectedNotificator = null;
	private Drawable selectedNotificator = null;
	private TextView textNotiticatior = null;
	private int currentIndex = 0;
	
	public HotspotNotificationBannerManager(Context context, ArrayList<HelpDataInfomation> hotspostBuffer){
		
		this.hotspotNotificationBanner = LayoutInflater.from(context).inflate(R.layout.hotspot_notification_banner_layout, null);
		this.hotspostBuffer = hotspostBuffer;
		this.unselectedNotificator = context.getResources().getDrawable(R.drawable.unselected_notification_image);
		this.selectedNotificator = context.getResources().getDrawable(R.drawable.selected_notification_image);
		this.hotspotImageNotificationViewBuffer = new ArrayList<ImageView>();
		
		FrameLayout frameLayout = (FrameLayout) hotspotNotificationBanner.findViewById(R.id.hotsport_notification_banner_linearlayout);
		
		textNotiticatior = new TextView(context);
		textNotiticatior.setTextColor(0xffffffff);
		textNotiticatior.setTextSize(17);
		frameLayout.addView(textNotiticatior, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
		
		LinearLayout linear = new LinearLayout(context);
		linear.setPadding(0, 0, Util.dip2px(context, 5), Util.dip2px(context, 7));
		frameLayout.addView(linear, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.BOTTOM));
		
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		params.setMargins(Util.dip2px(context, 2.5f), 0, Util.dip2px(context, 2.5f), 0);
		for (int i = 0; i < hotspostBuffer.size(); i++){
			ImageView view = new ImageView(context);
			view.setImageDrawable(unselectedNotificator);
			linear.addView(view, params);
			hotspotImageNotificationViewBuffer.add(view);
		}
		
		if(hotspostBuffer.size() > 0){
			hotspotImageNotificationViewBuffer.get(currentIndex).setImageDrawable(selectedNotificator);
			textNotiticatior.setText(hotspostBuffer.get(currentIndex).getTitle());
		}
	}
	
	public void setCurrentIndex(int index){
		if (currentIndex == index || index >= hotspotImageNotificationViewBuffer.size()) return;
		hotspotImageNotificationViewBuffer.get(currentIndex).setImageDrawable(unselectedNotificator);
		currentIndex = index;
		hotspotImageNotificationViewBuffer.get(currentIndex).setImageDrawable(selectedNotificator);
		textNotiticatior.setText(hotspostBuffer.get(currentIndex).getTitle());
	}
	
	public View getHotspotBanner(){
		return hotspotNotificationBanner;
	}
	
}
